Okay, so in today's lesson we are going to have a look at another function called the weight function.
Now this is quite an easy function.
It's commonly used just like the print and warn functions we learned earlier on.
Um so add a script into your game.
This time however, we're going to add it into server script service.
So go over to Server Script Service.
In the explorer click the plus and add in a script.
Okay.
The reason why we're adding it in server script service is because sometimes you can put a script into
there instead of putting it in the workspace.
Okay, different scripts go in different places.
Um, but for your standard scripts, they can go in the workspace if they're controlling a certain part,
but usually if they're not controlling a part, you put them into server script service.
But whichever way you put them in, it doesn't matter too much.
Um, I'm going to delete the print hello World a bit.
Okay, so the wait function, um, basically allows you to pause the script for a selected amount of
time so you could choose how long you want the script to pause for.
And this is really useful because last lessons when we were looking at changing properties, if you
tried out, if you if you did it yourself and you tried it out, it changes them, changes them instantly
before you can even get into the game.
It's already changed those properties, and sometimes it's nice to be able to see it changing in real
time.
So let's reference the part.
So because we're in server script service we can't use script dot parent.
Well we could but you have to say script dot parent dot parent to get to the game.
It'd be easier just to write game dot instead.
So game dot workspace dot part okay let's start off by this part here.
Let's change the color of it okay dot lots.
Let's say let's do dot color is equal to color three dot new.
And let's change it to let's say um this color here okay.
After that.
So I want it about to do it instantly.
Okay.
Then I would like a bit of time to load into the game and look at the part before it changes more properties.
Okay.
So I'm going to write a wait function to do it.
It goes on a separate line underneath okay.
And the keyword for this function, the name of the function is simply just wait okay.
And just like how with the print and warn functions it's a function.
So it contains a pair of brackets or parentheses after it.
Okay.
Um, so inside here you literally just write a number of how many seconds you want it to wait.
So if you want to wait one, you would just write like that.
And that would pause the script there for a second.
And then it carries on.
Okay.
So let's say after um, let's say four seconds, I want to change something else.
I want to change my material.
So let's say game dot workspace dot part dot material is equal to enum dot material dot.
And let's pick a neon for example okay.
So let's try this one out.
So if we run the game it should instantly change like a teal kind of color.
There we go.
And in a few seconds it should turn neon.
There we go.
Perfect.
So it's quite cool I think, to see the code actually writing change things in real time.
Um, and that's what the wait function allows you to do.
Um, also, if you want to wait a specific amount of time for things, when you get into more complex
scripts like leaderboards, for example, that might update once every 30s you'd want to put a wait
of 30 in there, for example.
Okay, so the wait function is very useful, but it's also very easy.
It's just the wait and then brackets and the number you want in there as well.
Okay.
One thing you might see, you might notice that I've done here is that I've left spaces in between.
And I haven't just written it like this here.
Okay.
It's the same kind of thing like the brackets.
Sorry.
It's the same thing.
Like with the spaces.
Um, with after the colons and after the equal signs.
It's not incorrect.
It's just easier to read this way.
And coding, when you're writing code, you don't just write it all in one big block.
You do leave spaces, okay?
And it kind of works like paragraphs.
Um, when you're when you're writing stuff.
Okay, you typically use a new paragraph when you're talking about a new thing or a different time or
something like.
Okay.
So because we're because time has passed, we've got a different time now it's good just to leave a
space just to make that obvious.
Okay.
Obviously for my code here, which is five lines long, it's not going to make too much of a difference.
But when your code is much longer, it's just good practice to get into.
Because when you when you're making more difficult code, it's making it much easier to read and understand.
Okay, for both of you and other people, if you ever want help, um, help on your script and it's
very difficult to read, it's going to be more difficult for other people to help you on it, for example.
Okay.
Which is why I would recommend writing those.
Um.
Um, I'd recommend leaving spaces before and after the wait.
Okay.
And that's it.
That's all you need to know about the wait function.
So it's a simple function that allows you to see changes done in real time, which is quite cool.
Okay, so have a try out of that.
And next lesson we're going to have a look at what variables are.